package ch1.base;

public class UseJoin {

    /**
     * 女神线程
     */
    private static class Goddess implements Runnable {
        private Thread thread;

        public Goddess() {

        }

        public Goddess(Thread thread) {
            this.thread = thread;
        }

        @Override
        public void run() {
            System.out.println("Goddess开始排队打饭。。。");
            if (thread != null) {
                try {
                    thread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Goddess打饭完成。。。");
        }
    }

    /**
     * 女神男朋友线程
     */
    private static class GoddessGirlFriend implements Runnable {
        @Override
        public void run() {
            try {
                Thread.sleep(2000);
                System.out.println("Goddess男朋友开始排队打饭。。。");
                System.out.println("Goddess男朋友打饭完成。。。");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * main线程是lison老师
     *
     * @param args 参数
     */
    public static void main(String[] args) {
        //lison老师线程
        Thread lisonThread = Thread.currentThread();
        System.out.println("lison老师开始排队打饭。。。");


        //女神男朋友线程
        GoddessGirlFriend goddessGirlFriend = new GoddessGirlFriend();
        Thread goddessGirlFriendThread = new Thread(goddessGirlFriend);


        //女神线程
        Goddess goddess = new Goddess(goddessGirlFriendThread);
        Thread goddessThread = new Thread(goddess);


        goddessThread.start();
        goddessGirlFriendThread.start();

        try {
            goddessThread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("lison老师打饭完成。。。");
    }
}